package service;
import java.util.List;

import model.User;
import dao.UserDaoImpl;
import dao.UserDao;
public class UserService implements IUserService{
	UserDaoImpl dao1;
	public UserService() throws Exception{
		super();
		dao1=new UserDaoImpl();
	}
	public boolean insertUser(User user) throws Exception  {
		if(dao1.findByName(user.getUsername())==null){
			dao1=new UserDaoImpl();
			return this.dao1.insertUser(user);
			}
		else 
			return false;
	}
	public boolean updateUser(User user ) throws Exception{
		return this.dao1.updateUser(user);
	}

	public boolean deleteUser(User user)throws Exception {
		return this.dao1.deleteUser(user);
	}
	public List<User> findAll() throws Exception {
		return this.dao1.findAll();
	}
	public User findByName(String username) throws Exception {
		return this.dao1.findByName(username);
	}
	public boolean checkName(String username,String password) throws Exception{
		boolean test=false;
		User user;
		if(dao1.IsName(username))
			test=false;//用户名不存在
		else{
			dao1=new UserDaoImpl();
			user=dao1.findByName(username);
			if(user.getPassword().equals(password))
				test=true;
			else
				test=false;
		}
		return test;
	}
	public boolean findUser(String username) throws Exception {
		return this.dao1.IsName(username);
	}
	public User findById(int Id) throws Exception {
	   return this.dao1.findById(Id);
	}
}

